import java.util.Arrays;

public class Test {
    /**
     * 作业
     */
    //判断数组中是否存在三个连续的奇数
    public static boolean fuc5(int[] array){
        int count=0;
        for (int i = 0; i < array.length; i++) {
            if(array[i] %2!=0){
                count++;
                if(count==3){
                    return true;
                }
            }else{
                count=0;
            }
        }
        return false;
    }
    public static void main(String[] args) {
        int[] array={1,2,3,5,7};
        System.out.println(fuc5(array));
    }



    //找数组中总是存在的数值
    public static int fuc4(int[] array){
        Arrays.sort(array);
        return array[array.length/2];
    }
    public static void main4(String[] args) {
        int [] array={1,1,2,2,2};
        System.out.println(fuc4(array));
    }
    public static int fuc3(int[] array){
        int ret =0;
        for (int i = 0; i < array.length; i++) {
            ret^=array[i];
        }
        return ret;
    }

    public static void main3(String[] args) {
        int [] array={1,2,3,2,1};
        System.out.println(fuc3(array));
    }
    //返回targer值 [2,7,11,15]
    public static int[] fuc2(int[] array,int target){
        int[] ret={-1,-1};
        for (int i = 0; i <array.length; i++) {
            for (int j = i+1; j < array.length; j++) {
                if(array[i]+array[j]==target){
                    ret[0]=i;
                    ret[1]=j;
                    return ret;
                }
            }
        }
        return ret;
    }
    public static void main2(String[] args) {
        int []array={2,7,11,15};
        int[] ret= fuc2(array,9);
        System.out.println(Arrays.toString(ret));
    }
    //奇偶交换位置   1 2 3 4
    public static void fuc(int [] array){
        int i=0;
        int j=array.length-1;
        while(i<j){

            while (i<j && array[i]%2!=0){
                i++;
            }
            while(i<j && array[j]%2==0){
                j--;
            }
             int temp=array[i];
             array[i]=array[j];
             array[j]=temp;
        }

    }
    public static void main1(String[] args) {
        int [] array={1,4,5,7,8,4};
        fuc(array);
        System.out.println(Arrays.toString(array));
    }
}
